package com.kfm.base.thread.day03;

public class Demo18 {

    public static void main(String[] args) {
        new MyThread1().start();
        new MyThread2().start();

    }
}
class MyThread1 extends Thread{

    // 余额
    public static int money = 10000;
    // 锁
    public static Object lock = new Object();

    @Override
    public void run() {
        while(true) {
            synchronized (lock){
                if (money != 10000) {
                    System.out.println("我的余额变了");
                    break;
                }
            }
        }

    }

}

class MyThread2 extends Thread{

    @Override
    public void run() {
        synchronized (MyThread2.class) {
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            MyThread1.money = 1;
            System.out.println("偷到了");
        }
    }
}